<!-- Veljko Jovanovic -->
<?php
session_start();

include("konekcija_sa_bazom.php");

$kom=$_POST["kom"];
$pok = $_POST["id"];

if (isset($_SESSION["id"])) $kor = $_SESSION["id"];
else $kor = 0;

if (isset($_SESSION["tip"])) $tipKorisnika = $_SESSION["tip"];
else $tipKorisnika = 0;

mysql_query("SET NAMES utf8");
$querry="INSERT INTO komentar (sadrzaj, datumKreiranja, idKorisnik) values('$kom', CURRENT_TIMESTAMP(), '$kor')";

mysql_query($querry);

$idKom = mysql_insert_id();
$querry="INSERT INTO komentarpoklona (idPoklon, idKomentar) values('$pok', '$idKom')";

mysql_query($querry);

						?>
                        <table bgcolor="#DEF7F4">
                        	<tr >
                            <td>
                            <textarea id="kom" cols = "70" rows="3"> 
                            </textarea>
                            </td>
                            </tr>
                            <tr align="right">
                            <td align="right">
                            <a href="#" class="button" onclick ="ubaciKomentar(<?php echo $pok ?>)" style="float:right; font-size:14px; ">Postavi</a>
                     
                
                            </td>
                            </tr>
                            
                        </table>
					<?php
                   
					
					$querry="SELECT * FROM komentar AS k, komentarpoklona AS kp WHERE k.idKomentar = kp.idKomentar AND kp.idPoklon = $pok ORDER BY k.datumKreiranja DESC";
					$result = mysql_query($querry);
					for ( $i = 0; $i < mysql_num_rows($result); $i++)
					{
						$komentar = mysql_fetch_array($result);
						
						$sql="SELECT * FROM korisnik WHERE idKorisnik = '".$komentar['idKorisnik']."'";
						$korisnici = mysql_query($sql);
						$postavioK = mysql_fetch_array($korisnici);
						
						echo "<table>";
						echo '<tr bgcolor=';
						echo "#DEF7F4";
						echo '><td width="600"><div style="background:#FFF"> ';
						if (isset($postavioK['ime'])) echo '<font size = "2"><a href="Profilkorisnika.php?id='.$postavioK["idKorisnik"].'">'.$postavioK["ime"].'</a>: </font>';
						echo $komentar['sadrzaj']."</div>";
						echo '<p align="right" style="margin:0">'.$komentar['datumKreiranja'];
						if ($tipKorisnika == "A") echo '<input type="button" onclick ='.'"'.'return ukloniKomentar('.$komentar['idKomentar'].','.$pok.')" id="btnSearch" class="button" value="Ukloni" style="padding-bottom:1px; padding-top:1px; font-size:13px; margin-top:1px; vertical-align:middle">';
						echo '<input type="button" onclick ='.'"'.'return prikaziPopUp('.$komentar['idKomentar'].')" id="btnSearch" class="button" value="Prijavi" style="padding-bottom:1px; padding-top:1px; font-size:13px; margin-top:1px; vertical-align:middle"></p></td></tr></table></br>';
					
				}
				
                
mysql_close($veza);



?>

